package com.pj.hellomvvm.ui.activity

import android.os.Bundle

import com.blankj.utilcode.constant.PermissionConstants
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.PermissionUtils
import com.pj.common.base.BaseActivity
import com.pj.hellomvvm.R
import com.pj.hellomvvm.databinding.ActivitySampleMainBinding
import com.pj.hellomvvm.ui.adapter.HomePagerAdapter
import com.pj.hellomvvm.ui.fragment.AppUIFragment
import com.pj.hellomvvm.ui.fragment.OtherFragment
import com.pj.hellomvvm.ui.fragment.WidgetFragment
import com.pj.hellomvvm.utils.DrawableUtils
import com.pj.hellomvvm.viewmodel.MainViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : BaseActivity<MainViewModel, ActivitySampleMainBinding>() {

    override fun getLayoutRes(): Int = R.layout.activity_sample_main

    override fun initData(savedInstanceState: Bundle?) {
        super.initData(savedInstanceState)
        initPermissions()
        initTabs()
        initPager()
    }

    private fun initTabs() {
        val builder = mBinding.tabs.tabBuilder()
        val widget = builder.setSelectedDrawable(
            DrawableUtils.vectorDrawable(
                this,
                R.drawable.ic_tab_widget,
                R.color.colorPrimary
            )
        )
            .setNormalDrawable(
                DrawableUtils.vectorDrawable(
                    this,
                    R.drawable.ic_tab_widget,
                    R.color.back_666
                )
            )
            .setText("控件").build(this)

        val appUI = builder.setSelectedDrawable(
            DrawableUtils.vectorDrawable(
                this,
                R.drawable.ic_tab_app,
                R.color.colorPrimary
            )
        )
            .setNormalDrawable(
                DrawableUtils.vectorDrawable(
                    this,
                    R.drawable.ic_tab_app,
                    R.color.back_666
                )
            )
            .setText("仿界面").build(this)
        val other = builder.setSelectedDrawable(
            DrawableUtils.vectorDrawable(
                this,
                R.drawable.ic_tab_other,
                R.color.colorPrimary
            )
        )
            .setNormalDrawable(
                DrawableUtils.vectorDrawable(
                    this,
                    R.drawable.ic_tab_other,
                    R.color.back_666
                )
            )
            .setText("其它").build(this)
        mBinding.tabs.addTab(widget).addTab(appUI).addTab(other)

    }

    private fun initPager(){
        val pagerAdapter = HomePagerAdapter(supportFragmentManager, mutableListOf(WidgetFragment(),AppUIFragment(),OtherFragment()))
        mBinding.apply {
            pager.adapter = pagerAdapter
            tabs.setupWithViewPager(pager,false)
        }
    }


    private fun initPermissions() {
        PermissionUtils.permission(PermissionConstants.STORAGE,PermissionConstants.CAMERA)
            .callback(object : PermissionUtils.SimpleCallback {
                override fun onGranted() {
                    LogUtils.d("权限申请通过")
                }

                override fun onDenied() {

                    //.create(com.qmuiteam.qmui.R.style.QMUI_Dialog).show()
                }
            }).request()
    }

    override fun finish() {
        super.finish()
        overridePendingTransition(0, 0)
    }


    /*override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (item.itemId == R.id.test){
            TestRecyclerviewActivity.actionStart(this)
        }
        return super.onOptionsItemSelected(item)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.main_menu,menu)
        return super.onCreateOptionsMenu(menu)
    }*/
}